#include "../../common/my_tool.hpp"
#include "../../server/rpc_server.hpp"

void Add(const Json::Value& req, Json::Value& rsp)
{
    int num1 = req["num1"].asInt();
    int num2 = req["num2"].asInt();
    rsp = num1 + num2;
}

int main()
{
    // 1.使用工厂注册服务
    std::unique_ptr<jsonrpc::server::SDescribeFactory> desc_factory(new jsonrpc::server::SDescribeFactory());
    desc_factory->setMethod("Add");
    desc_factory->setParamsDescribe("num1", jsonrpc::server::VType::INTEGRAL);
    desc_factory->setParamsDescribe("num2", jsonrpc::server::VType::INTEGRAL);
    desc_factory->setReturenType(jsonrpc::server::VType::INTEGRAL);
    desc_factory->setServiceCallBack(Add);

    jsonrpc::server::RpcServer server(jsonrpc::Address("127.0.0.1",9090), true, jsonrpc::Address("127.0.0.1",8080));
    server.registerMethod(desc_factory->build());
    server.start();

    return 0;
}